﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeGame.Networking.Clientside.ServerClientPackets
{
    class GlobalChatPacket : ClientPacket
    {
        private string Nickname;
        private string Message;

        public override bool Validate(Lidgren.Network.NetIncomingMessage msg)
        {
            this.Nickname = msg.ReadString();
            this.Message = msg.ReadString();

            if (!this.ValidateString(this.Nickname))
            {
                return false;
            }

            if (!this.ValidateString(this.Message))
            {
                return false;
            }

            return true;
        }

        public override void Handle()
        {
            if (string.IsNullOrWhiteSpace(this.Nickname))
            {
                Singletons.Console.Print(this.Message, Singletons.NetworkColor);
            }
            else
            {
                Singletons.Console.Print(this.Nickname + " : " + this.Message, Singletons.NetworkColor);
            }
        }

        public override ServerClientNet GetID()
        {
            return ServerClientNet.GlobalAnounce;
        }

        public override void Handle(Lidgren.Network.NetIncomingMessage message)
        {
            this.Validate(message);
            this.Handle();
        }

    }
}
